using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ManualTargetSystem : Singleton<ManualTargetSystem>
{
    [SerializeField] private ArrowView arrowView;
    [SerializeField] private LayerMask targetLayerMask;

    public void StartTarget(Vector3 startPosition)
    {
        if (arrowView != null)
        {
            arrowView.gameObject.SetActive(true);
            arrowView.SetupArrow(startPosition);
        }
    }

    public EnemyView EndTargeting(Vector3 endPosition)
    {
        if (arrowView != null)
        {
            arrowView.gameObject.SetActive(false);
        }

        Vector3 mousePos = Input.mousePosition;
        mousePos.z = Mathf.Abs(Camera.main.transform.position.z); // �����������ƽ�����

        Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);

        // ��Z����������
        Ray ray = new Ray(worldPos, Vector3.back);

        if (Physics.Raycast(ray, out RaycastHit hit, 50f, targetLayerMask))
        {
            if (hit.transform.TryGetComponent<EnemyView>(out EnemyView enemyView))
            {
                return enemyView;
                // Debug.Log($"[ManualTargetSystem] �ɹ�����Ŀ��: {enemyView.name}");
            }
        }

        return null;
    }
}
